<?php

namespace app\utils;

use yii\db\ActiveRecord;
use yii\web\IdentityInterface;
use yii\web\User;

class UserUtil {
    /**
     * 获取指定模块下的用户实例
     * @param string $module_name 模块名称
     * @return IdentityInterface|null
     * @throws \Throwable
     * @throws \yii\base\InvalidConfigException
     */
    public static function getModuleUserIdentity($module_name){
        /**
         * @var User $user
         */
        $user = \Yii::$app->getModule($module_name)->get("user");
        if($user->getIsGuest()){
            return null;
        }
        return $user->getIdentity();
    }
}